﻿CloudDisk.Admin.AccountPanel = (function(cfg){
    var el = $('#accountPanel');
	
	var tpl = [ 
        '<div style="padding:40px 10px 0 50px;">',	
			'<div class="form-item">', 
				'<label>Email:</label>',
				'<input name="email" type="text" class="input-text" disabled="true">',
			'</div>',
			'<div class="form-item">', 
				'<label>用户名:</label>',
				'<input name="userName" type="text" class="input-text">',
			'</div>',
			'<div class="form-item">', 
				'<label>当前密码:</label>',
				'<input name="oldPwd" type="password" class="input-text">',
			'</div>',
			'<div class="form-item">', 
				'<label>新的密码:</label>',
				'<input name="newPwd" type="password" class="input-text">',
			'</div>',
			'<div class="form-item">', 
				'<label>重复密码:</label>',
				'<input name="newPwd2" type="password" class="input-text">',
			'</div>',		
			'<div class="add-member-ops" style="margin-top:20px;">',
				'<button action="save">保存</button>',
			'</div>',
		'</div>'
	].join('');
	
	var initialized = false;
	
    return {
	    init: function(){
		    var that = this;
			el.html(tpl);
		    el.find('.adm-member-toolbar button').click(function(){
			    CloudDisk.Admin.AddMemberWindow.open(function(o){			
					CloudDisk.Admin.SessionMgr.addUser({
					    user_name: o.email,
						user_type: o.memberType,
						email: o.email,
						password: '123456',
						group_id: o.groupId
					}, function(){			    

					});
				});
			});
			
			el.find('.search-bar input').keyup(function(){
			    var filteredMembers = [];
				var key = $(this).val();
				var body = el.find('.adm-member-body');
				for(var i = 0; i < members.length; ++i){
				    var m = members[i];
					if(m.user_name.indexOf(key) > -1 || m.email.indexOf(key) > -1){
					    filteredMembers.push(m);
					}
				}
				body.empty();
				for(var i = 0; i < filteredMembers.length; ++i){
				    body.append(that.createItem(filteredMembers[i]));
				}
			});
		},
		
		activate: function(){
		    var that = this;
		    el.show();
			if(!initialized){
			    that.init();
				initialized = true;
			}


		}
	};
})();